home *** CD-ROM | disk | FTP | other *** search
/ 3D GFX / 3D GFX.iso / pcutils / windows / 3dgpl / code / demo / demo.c < prev   
Encoding:
C/C++ Source or Header  |  1995-12-31  |  5.2 KB  |  127 lines

  1. /** 3DGPL *************************************************\
  2.  * A demo allowing to rotate a polygon rendering it as    *
  3.  * either ambient, shaded or textured. ( <TAB> to change  *
  4.  * rendering option ).                                    *
  5.  *                                                        *
  6.  *  If it doesn't work:                                   *
  7.  *   1) make sure you are using right hardware interface  *
  8.  *      source and your system sutisfies requirements     *
  9.  *      described in it's head comment.                   *
  10.  *   2) if this application does quit on <ENTER> but      *
  11.  *      shows nothing, adjust colour intensities assigned *
  12.  *      in main(), hardware interface function doesn't    *
  13.  *      convert them.                                     *
  14.  *   3) if the demo crashes recompile with bigger stack.  *
  15.  *                                                        *
  16.  *  (6/1995) By Sergei Savhenko. (savs@cs.mcgill.ca).     *
  17.  *  Copyright (c) 1995 Sergei Savchenko.                  *
  18.  *  THIS SOURCE CODE CAN'T BE USED FOR COMERCIAL PURPOSES *
  19.  *  WITHOUT AUTHORISATION                                 *
  20. \**********************************************************/
  21.  
  22. #include <stdio.h>
  23. #include "../hardware/hardware.h"
  24. #include "../engine/engine.h"
  25. #include "../graphics/graphics.h"
  26. #include "../trans/trans.h"
  27.  
  28. unsigned char alp=0,bet=0,gam=0;
  29. int x=0,y=0,z=200;
  30.  
  31. unsigned char texture[16][16]=
  32. {
  33.  {0xef,0xee,0xed,0xec,0xeb,0xea,0xe9,0xe8,0xe7,0xe6,0xe5,0xe4,0xe3,0xe2,0xe1,0xe0},
  34.  {0xef,0x55,0x55,0x55,0x55,0x55,0x55,0xe8,0xe7,0x55,0x55,0x55,0x55,0x55,0xe1,0xe0},
  35.  {0xef,0xee,0xed,0xec,0xeb,0x55,0xe9,0xe8,0xe7,0x55,0xe5,0xe4,0xe3,0xe2,0x55,0xe0},
  36.  {0xef,0xee,0xed,0xec,0x55,0xea,0xe9,0xe8,0xe7,0x55,0xe5,0xe4,0xe3,0xe2,0x55,0xe0},
  37.  {0xef,0xee,0xed,0x55,0x55,0x55,0x55,0xe8,0xe7,0x55,0xe5,0xe4,0xe3,0xe2,0x55,0xe0},
  38.  {0xef,0xee,0xed,0xec,0xeb,0xea,0x55,0xe8,0xe7,0x55,0xe5,0xe4,0xe3,0xe2,0x55,0xe0},
  39.  {0xef,0x55,0x55,0x55,0x55,0x55,0xe9,0xe8,0xe7,0x55,0x55,0x55,0x55,0x55,0xe1,0xe0},
  40.  {0xef,0xee,0xed,0xec,0xeb,0xea,0xe9,0xe8,0xe7,0xe6,0xe5,0xe4,0xe3,0xe2,0xe1,0xe0},
  41.  {0xef,0xee,0x77,0x77,0xeb,0xea,0x76,0x76,0x76,0xe6,0xe5,0x75,0xe3,0xe2,0xe1,0xe0},
  42.  {0xef,0x77,0xed,0xec,0x77,0xea,0x76,0xe8,0xe7,0x76,0xe5,0x75,0xe3,0xe2,0xe1,0xe0},
  43.  {0xef,0x77,0xed,0xec,0xeb,0xea,0x76,0xe8,0xe7,0x76,0xe5,0x75,0xe3,0xe2,0xe1,0xe0},
  44.  {0xef,0x77,0xed,0xec,0xeb,0xea,0x76,0xe8,0xe7,0x76,0xe5,0x75,0xe3,0xe2,0xe1,0xe0},
  45.  {0xef,0x77,0xed,0x77,0x77,0xea,0x76,0x76,0x76,0xe6,0xe5,0x75,0xe3,0xe2,0x75,0xe0},
  46.  {0xef,0x77,0xed,0xec,0x77,0xea,0x76,0xe8,0xe7,0xe6,0xe5,0x75,0xe3,0xe2,0x75,0xe0},
  47.  {0xef,0xee,0x77,0x77,0x77,0xea,0x76,0xe8,0xe7,0xe6,0xe5,0x75,0x75,0x75,0x75,0xe0},
  48.  {0xef,0xee,0xed,0xec,0xeb,0xea,0xe9,0xe8,0xe7,0xe6,0xe5,0xe4,0xe3,0xe2,0xe1,0xe0}
  49. };
  50.  
  51. struct M_polygon a= {M_AMBIENT,56,NULL,0,0,0,0,4,{0,3,6,9,0}};
  52. struct M_polygon s= {M_SHADED,0,NULL,0,0,0,0,4,{0,5,3,42,6,58,9,21,0,11}};
  53. struct M_polygon t= {M_TEXTURED,0,(unsigned char*)texture,4,6,0,3,4,
  54.                     {0,0,64,3,64,64,6,64,0,9,0,0,0,0,64}};
  55. struct M_polygon *p=&t;
  56. int m_no_verteces=4;
  57. int verteces[]={-50,50,0,50,50,0,50,-50,0,-50,-50,0};
  58. int m_no_vectors=2;
  59. int vectors[]={100,0,0,0,100,0};
  60.  
  61. /**********************************************************\
  62.  * being called to treat key press.                       *
  63. \**********************************************************/
  64.  
  65. void app_handler(int kk)
  66. {
  67.  switch(kk)
  68.  {
  69.   case HW_KEY_ENTER:       HW_quit_event_loop(); break;
  70.   case HW_KEY_ARROW_RIGHT: gam+=10; break;
  71.   case HW_KEY_ARROW_LEFT:  gam-=10; break;
  72.   case HW_KEY_ARROW_UP:    bet+=10; break;
  73.   case HW_KEY_ARROW_DOWN:  bet-=10; break;
  74.   case 'X': case 'x':      alp+=10; break;
  75.   case 'S': case 's':      alp-=10; break;
  76.   case 'A': case 'a':      z-=10;   break;
  77.   case 'Z': case 'z':      z+=10;   break;
  78.   case HW_KEY_TAB: if(p==&a) p=&s; else if(p==&s) p=&t; else p=&a;
  79.  }
  80. }
  81.  
  82. /**********************************************************\
  83.  * being called to render a frame.                        *
  84. \**********************************************************/
  85.  
  86. void app_main(void)
  87. {
  88.  int tmp_verteces[50];
  89.  int tmp_vectors[50];
  90.  char str[100];
  91.  
  92.  G_clear();
  93.  
  94.  T_set_self_rotation(alp,bet,gam);
  95.  T_self_rotation(verteces,tmp_verteces,m_no_verteces);
  96.  T_translation(tmp_verteces,tmp_verteces,m_no_verteces,x,y,z);
  97.  T_self_rotation(vectors,tmp_vectors,m_no_vectors);
  98.  M_render_polygon(p,tmp_verteces,tmp_vectors);
  99.  
  100.  sprintf(str,"3DGPL <%d %d %d %d>",alp,bet,gam,z); G_text(0,0,str,63);
  101.  if(p==&a) G_text(200,0,"AMBIENT",63);
  102.  if(p==&s) G_text(200,0,"SHADED",63);
  103.  if(p==&t) G_text(200,0,"TEXTURED",63);
  104.  G_text(0,190,"<ARROWS> <TAB> <A> <Z> <S> <X> <ENTER>",63);
  105.  
  106.  HW_blit();
  107. }
  108.  
  109. /**********************************************************\
  110.  * assignes colours and starts the event loop.            *
  111. \**********************************************************/
  112.  
  113. int main(void)
  114. {
  115.  struct HW_colour pal[256];
  116.  int i;
  117.  
  118.  for(i=0;i<256;i++) { pal[i].hw_r=i; pal[i].hw_g=0; pal[i].hw_b=0; }
  119.  HW_open_screen(NULL,"3DGPL",pal,G_init_graphics()); T_init_math();
  120.  HW_run_event_loop(app_main,app_handler);
  121.  HW_close_screen();
  122.  
  123.  return(1);
  124. }
  125.  
  126. /**********************************************************/
  127.